package com.ruoyi.generator.service.impl;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.generator.entity.ExportWaterQuality;
import com.ruoyi.generator.mapper.ExportWaterQualityMapper;
import org.apache.velocity.util.ArrayListWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.ruoyi.generator.service.IExportWaterQualityService;

/**
 * 出口水质监测（全参数）Service业务层处理
 *
 * @author ruoyi
 * @date 2025-09-10
 */
@Service
public class ExportWaterQualityServiceImpl implements IExportWaterQualityService
{
    @Autowired
    private ExportWaterQualityMapper exportWaterQualityMapper;

    /**
     * 查询出口水质监测（全参数）
     *
     * @param id 出口水质监测（全参数）主键
     * @return 出口水质监测（全参数）
     */
    @Override
    public ExportWaterQuality selectExportWaterQualityById(Long id)
    {
        return exportWaterQualityMapper.selectExportWaterQualityById(id);
    }

    /**
     * 查询出口水质监测（全参数）列表
     *
     * @param exportWaterQuality 出口水质监测（全参数）
     * @return 出口水质监测（全参数）
     */
    @Override
    public List<ExportWaterQuality> selectExportWaterQualityList(ExportWaterQuality exportWaterQuality)
    {
        String start="";
        String end="";
        DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        if(exportWaterQuality.getStartTime()!=null && exportWaterQuality.getStartTime()!=""){
            LocalDateTime dateTime = LocalDateTime.parse(exportWaterQuality.getStartTime(), inputFormatter);
            start = dateTime.format(outputFormatter);
            exportWaterQuality.setStartTime(start);
        }
        if(exportWaterQuality.getEndTime()!=null && exportWaterQuality.getEndTime()!=""){
            LocalDateTime dateTime = LocalDateTime.parse(exportWaterQuality.getEndTime(), inputFormatter);
            end = dateTime.format(outputFormatter);
            exportWaterQuality.setEndTime(end);
        }
        List<ExportWaterQuality> list=new ArrayList<>();
        if(exportWaterQuality.getWaterie() == null || exportWaterQuality.getWaterie()==""){
            list=exportWaterQualityMapper.selectAllWaterQualityList(exportWaterQuality);
        }else if (exportWaterQuality.getWaterie().equals("export")){
            list=exportWaterQualityMapper.selectExportWaterQualityList(exportWaterQuality);
        }else{
            list=exportWaterQualityMapper.selectImportWaterQualityList(exportWaterQuality);
        }

        return list;
    }

    /**
     * 新增出口水质监测（全参数）
     *
     * @param exportWaterQuality 出口水质监测（全参数）
     * @return 结果
     */
    @Override
    public int insertExportWaterQuality(ExportWaterQuality exportWaterQuality)
    {
        exportWaterQuality.setCreateTime(DateUtils.getNowDate());
        return exportWaterQualityMapper.insertExportWaterQuality(exportWaterQuality);
    }

    /**
     * 修改出口水质监测（全参数）
     *
     * @param exportWaterQuality 出口水质监测（全参数）
     * @return 结果
     */
    @Override
    public int updateExportWaterQuality(ExportWaterQuality exportWaterQuality)
    {
        return exportWaterQualityMapper.updateExportWaterQuality(exportWaterQuality);
    }

    /**
     * 批量删除出口水质监测（全参数）
     *
     * @param ids 需要删除的出口水质监测（全参数）主键
     * @return 结果
     */
    @Override
    public int deleteExportWaterQualityByIds(Long[] ids)
    {
        return exportWaterQualityMapper.deleteExportWaterQualityByIds(ids);
    }

    /**
     * 删除出口水质监测（全参数）信息
     *
     * @param id 出口水质监测（全参数）主键
     * @return 结果
     */
    @Override
    public int deleteExportWaterQualityById(Long id)
    {
        return exportWaterQualityMapper.deleteExportWaterQualityById(id);
    }
}
